package demo1;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class Demo {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
//        1.实例化Person并调用sayHello()方法
        /*
        优点:直接明了
        缺点:代码写死,不够灵活
         */
        Person p = new Person();
        p.sayHello();

//        2.反射调用
        /*
        优点:调用灵活
        缺点:需要编写大量反射代码
         */
        Class cls = Class.forName("demo1.Person");
        Person p1 = (Person) cls.newInstance();
        p1.sayHello();
//        3.Spring 容器
        AnnotationConfigApplicationContext ctx
                = new AnnotationConfigApplicationContext("demo1");
        Person p2 = ctx.getBean(Person.class);
        p2.sayHello();
    }
}
